import { _decorator, Component, instantiate, Label, Node, Prefab } from 'cc';
import { UIManager } from '../common/UIManager';
import { PrefabEnum } from '../common/PrefabEnum';
import { UserInfo } from '../common/UserInfo';
import { WorkerItem } from './WorkerItem';
const { ccclass, property } = _decorator;

@ccclass('WorkerList')
export class WorkerList extends Component {
    @property(Node)
    mask:Node
    @property(Node)
    close:Node
    @property(Label)
    title:Label
    @property(Node)
    layout:Node
    @property(Prefab)
    workerItem:Prefab

    start() {
        this.mask.on(Node.EventType.TOUCH_END, this.onClose, this)
        this.close.on(Node.EventType.TOUCH_END, this.onClose, this)

        this.getWorkerList()
        
    }

    getWorkerList(){
        let innerWorker = UserInfo.instance.getInnerWorker()
        let outerWorker = UserInfo.instance.getOuterWorker()
        let idleWorker = UserInfo.instance.getIdleWorker()
        let removeWorker = UserInfo.instance.getRemoveWorker()
        let idleRemoveWorker = UserInfo.instance.getIdleRemoveWorker()

        let list = [
            ...innerWorker,
            ...outerWorker,
            ...idleWorker,
            ...removeWorker,
            ...idleRemoveWorker
        ]
        console.log(list)

        for(let item of list){
            let node = instantiate(this.workerItem)
            this.layout.addChild(node)
            node.getComponent(WorkerItem).setData(item)
        }
    }

    onClose(){
        UIManager.instance.closeUI(PrefabEnum.WorkerList)
    }
}


